import Vue from "vue"
import Vuex from "vuex"
import createPersistedState from "vuex-persistedstate";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    page: {
      // 页面大小
      size: 4,
      // 当前页码
      current: 1,
      // 页码总数
      pageCount: 100,
      // 总记录数
      records: 1000,
      // 排序字段集合
      orders: []
    },
    user: {
      accountExpired: 0,
      accountNonExpired: true,
      accountNonLocked: true,
      authorities: [],
      credentialExpired: 0,
      credentialsNonExpired: true,
      enabled: true,
      id: '',
      password: "",
      roles: [],
      status: 1,
      token: "",
      userLocked: 0,
      username: ""
    }
  },
  getters: {
    getPageCount(state) {
      return Math.ceil(state.page.records / state.page.size);
    },
    getUser(){

    }
  },
  mutations: {
    CHANGE_USER(state,user){
     state.user=user;
    }
  },
  actions: {},
  plugins: [
    createPersistedState({
      // 存储方式：localStorage、sessionStorage、cookies
      storage: window.localStorage,
      // 存储的 key 的key值
      key: "vuex",
      render(state) {
        // 要存储的数据：本项目采用es6扩展运算符的方式存储了state中所有的数据
        return { ...state };
      }
    })
  ]

})
